<!--
Date: 2025-08-13
Copyright (c) 2025 Industrial Software Feature Database
-->
<template>
  <div class="table_div">
    <div class="return_btn">
      <el-tooltip content="返回"><img :src="back" alt="" @click="goBack" /></el-tooltip>
    </div>
    <!-- 材料库详情 -->
    <MaterialDetail
      :treeData="dataList"
      :canEdit="false"
      :modelId="props.modelId"
      heightClass="search_result_height"
    />
  </div>
</template>
<script setup name="UnifiedSearchResult">
import MaterialDetail from '@/views/material/component/MaterialDetail.vue';
import back from '@/assets/images/back.svg';
import { getUnifiedSearchResult } from '@/api/unifiedSearch';
const props = defineProps(['rowData', 'type', 'searchItem', 'modelId', 'params', 'tableData', 'modelList', 'sceneList', 'systemList', 'dataBaseList']);
const emits = defineEmits(['handleEvent']);
const treeData = ref([]);
const loading = ref(false);
const total = ref(0)
const tableData = ref([]);
const fieldList = ref([]);
const rowData = ref({});
const showMaterialDetail = ref(false);
const hasModelField = ref(false);
const tableName = ref('');
const dataList = ref([]);
const queryParams = ref({
  modelName: "",
  pageNum: 1,
  pageSize: 10,
})
const modelList = ref([])
const tableHeight = computed(() => {
  return 'calc(100vh - 200px)'
})
const goBack = () => {  
  if (props.type == 'LinkFromSearch') {
    emits('handleEvent', { 
      component: 'List', 
      modelId: props.modelId, 
      dataList: props.tableData,
      modelList: props.modelList,
      sceneList: props.sceneList,
      systemList: props.systemList,
      dataBaseList: props.dataBaseList,
      params: props.params
    });
  } else {
    emits('handleEvent', { 
      component: 'SearchDataList', 
      modelId: props.modelId, 
      params: props.params,
      row: props.rowData
    });
  }
}
const handleCurrentChange = (number) => {
  queryParams.value.pageNum = number;
  doQuery();
}
const doQuery = () => {  
  loading.value = true;
  getUnifiedSearchResult({
    ...queryParams.value,
    modelId: props.modelId
  }).then((res) => {
    console.log('res', res)
    if (res.data) {
      loading.value = false;
      // tableData.value = res.data.dataList;
      // fieldList.value = res.data.fieldList;
      // tableName.value = res.data.tableName;
      // hasModelField.value = fieldList.value.some(item => item.fieldType == '模型')
      dataList.value = res.data.dataList;
      total.value = res.data.total;
    }
  })
  .catch(() => {
    loading.value = false;
  }).finally(() => {
    loading.value = false;
  });
};
const doReset = () => {
  queryParams.value = {
    modelName: ''
  };
  doQuery();
};

onMounted(() => {
  props?.modelId && doQuery();
});
</script>
<style lang="less" scoped>
.table_div {
  position: relative;
  padding: 50px 20px 20px 20px;
  .return_btn {
    position: absolute;
    top: 0px;
    left: 0px;
    // width: 100%;
    > img {
      height: 45px;
      width: 45px;
      margin-left: 10px;
      cursor: pointer;
    }
  }
  .pagenation {
    display: flex;
    justify-content: end;
    padding-top: 10px;
  }
}
</style>